layui.use(['form', 'fsoft', 'pinyin'], function () {
  var $ = layui.$
    , form = layui.form
    , pinyin = layui.pinyin
    , fsoft = layui.fsoft;
  var rwid = $('#id').val();
  // 监听提交
  form.on('submit(save)', function (data) {
    var submitUrl = layui.cache['contentPath'] + '/sys-dept/save';
    if (rwid != undefined && rwid != "") {
      submitUrl = layui.cache['contentPath'] + '/sys-dept/modify';
    }
    fsoft.put(submitUrl, data.field, function (rs) {
      if (rs.code == 0) {
        fsoft.successMsg((rwid != undefined && rwid != "") ? "新增成功" : "编辑成功");
        xadmin.close();
      } else {
        fsoft.errorMsg(rs.msg);
      }
    });
    return false;
  });
  var mainAction = {
    renderSelect: function () {// 获取科室类别
      $.post(layui.cache['contentPath'] + '/sys-dict/findItemList', { dictId: '377916A28C1F4C1486F8AF7510E46CC8' }, function (data) {
        data = eval('(' + data + ')');
        if (data.code == "0") {
          xmSelect.render({
            el: '#xm-select-typeTree'
            , layVerify: "required"
            , name: "typeId"
            , radio: true
            , clickClose: true
            , initValue: [$("#typeId").val()],
            prop: { name: 'name', value: 'id' }, theme: { color: '#0081ff' },
            data: data.data, paging: true, pageSize: 5
          });
        }
      });
    }
  };
  mainAction.renderSelect();

  /* 编号自动赋值  */
  $(document).on("keydown", "#name", function () {
    if ($("#id").val() == "")
      // $("#code").val(pinyin.makePy($(this).val()));
      $("#code").val(pinyin.ConvertPinyin($(this).val()));
  });
});